1. Field of the Invention
This invention is generally directed to programming in a UNIX operating system and, more particularly, to the creation of links in such an operating system.
2. Description of the Related Art
Computers generally perform their most basic functions in accordance with their "operating system." An operating system is a program that runs other programs known as "applications programs," such as a word processor, invoked by the computer's user. The operating system also performs the elementary tasks associated with the computer's use, such as receiving input from the keyboard, sending output to a display or a printer, and controlling peripherals such as disk drives and printers. In some computers, the operating system might perform advanced tasks, such as maintaining security. Exemplary operating systems currently used include Windows.RTM. (a trademark of Microsoft Corp.), the Microsoft Disk Operating System (MS-DOS.RTM.) (a trademark of Microsoft Corp.), OS/2.RTM. (a trademark of IBM.), Linux.RTM. (a trademark of William R. Della Croce, Jr.), and UNIX.RTM. (a trademark of UNIXSYSTEM LABORATORIES, INC.).
UNIX is one popular operating system. The UNIX operating system is a "layered" operating system, and may be conceptualized as a plurality of concentric rings. The innermost ring, or the core, is the computer's hardware that physically executes the instructions of the software that comprises the two outer rings or layers. The outermost rings are called the "kernel" and the "shell," respectively. Applications programs are invoked and executed in the shell, or outermost ring, and the kernel controls the hardware, i.e., the innermost ring, to implement the instructions given by applications programs executing in the shell.
The kernel can be viewed as the "interface" between the applications programs and the hardware such that the applications programs in the shell never deal directly with the hardware. The kernel and the applications programs communicate through "system calls," which are requests by the applications programs for the kernel to perform specified services. Exemplary services that might be provided through system calls include accessing a file; manipulating a file by opening, closing, reading from, writing to, linking to, or executing the file; moving a file; enabling access to hardware devices; and managing system resources. However, there are many other types of system calls.
The kernel generally tracks files using "i-nodes." Each file has an i-node containing information about that file. For instance, the i-node may specify the ownership, creation date, last access date, last modification date, permissions, and the physical locations of the data blocks for the associated file. The kernel can then ascertain certain necessary or important information about the file in the performance of system calls.
Many system calls require one or more "links" to a file. A link is a pointer to a file. Links make it possible to reference a file by several different names and to access a file without specifying a full path for the file's location. Hard links allow two different files to show the same i-node and, hence, the same set of data blocks. Symbolic links may be conceptualized as two different files. One file contains the real data while the link itself is just a file containing the name of the real data file.
As an illustration, consider the output below generated by executing the command ls-li. The ls command is the system call for the kernel to list the contents of a directory. The suffix -li specifies that the -l and -i options for the ls command are to be implemented. These options specify an output of a `long` listing including the i-node number for the file. This command is being executed on a computer system named `pro`, short for "production". The output might look something like this:
1872396 -rwxr- 2 user nuucp 436 Oct 20 HardLink xr-x 13:43 1872396 -rw-r- 2 user nuucp 436 Oct 20 RealFile.PRO xr-x 13:42 1872397 lrwxr- 1 user nuucp 15 Oct 20 SymbolicLink@ xr-x 13:43 -&gt;RealFile.PRO
Each line of output corresponds to a file and includes, from left to right, the i-node, permissions, number of links, creator (i.e., user nuucp), size, creation date, and name for the file. The output also provides information on links to the files listed as is discussed below.
The above example shows an output for each of three files. The file named RealFile. PRO is a file that a user created using a text editor and is a standard UNIX file. The file named HardLink is a "hard" link to the file RealFile.PRO, evidenced in that the i-node number (column 1) is the same for both files. Also, the link count (in column three) is 2, indicating that there are two files in this file system that are referencing the same i-node number. The file named SymbolicLink is a link to the file named RealFile.PRO. Notice that the first letter in the second column is an l, which stands for link. Notice also that column six is the file size which in this case is 15 bytes. If one were able to look at the real contents of this file, it would be RealFile.PRO. However since the kernel knows this is a symbolic link, it treats the contents of the file as the name of the `real` file to access. The name of the link and the name of the real file can be entirely different.
There are differing limitations and advantages to hard links and symbolic links. First, for a hard link, the two file names must be in the same file system. Second, a directory may not be the target of a hard link. However there are two advantages to hard links as well. The data contained within the two files is identical and will stay identical. Also, no extra disk space is occupied since the two file names actually reference the same data blocks. There are advantages and disadvantages to symbolic links as well. Symbolic links can cross file system boundaries. Symbolic links can point to directories. Symbolic links require only an i-node entry and do not occupy any real data blocks. However symbolic links can also be misconfigured and set to point to a non-existent file.
The present invention is directed to the resolution of one or more of the problems set forth above.